﻿--KB_Currency-----------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KB_Currency]'))
DROP TABLE [KB_Currency]
GO
CREATE TABLE [KB_Currency](
	[Code] [varchar](3) NOT NULL,
	[Name] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_KB_Currency] PRIMARY KEY CLUSTERED ([Code] ASC)) ON [PRIMARY]
GO
--KB_Country-----------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KB_Country]'))
DROP TABLE [KB_Country]
GO
CREATE TABLE [KB_Country](
	[ISO2] [varchar](2) NOT NULL,
	[ISO3] [varchar](3) NULL,
	[Name] [nvarchar](100) NOT NULL,
	[CurrencyCode] [varchar](3) NULL,
	[NumberCode] [int] NULL,
	[Capital] [nvarchar](100) NULL,
 CONSTRAINT [PK_KB_Country] PRIMARY KEY CLUSTERED ([ISO2] ASC)) ON [PRIMARY]
GO
--ExchangeRate-----------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ExchangeRate]'))
DROP TABLE [ExchangeRate]
GO
CREATE TABLE [ExchangeRate](
	[Key] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
	[BaseCurrencyCode] [varchar](3) NOT NULL,
	[ToCurrencyCode] [varchar](3) NOT NULL,
	[RateValue] [decimal](18,4) NOT NULL DEFAULT 1,
	[EffectStamp] [date] NOT NULL,
 CONSTRAINT [PK_ExchangeRate] PRIMARY KEY CLUSTERED ([Key] ASC)) ON [PRIMARY]
GO
--ChinaProvince-----------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KB_ChinaProvince]'))
DROP TABLE [KB_ChinaProvince]
GO
CREATE TABLE [KB_ChinaProvince](
	[Key] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
	[Name] [nvarchar](20) NOT NULL,
	[ShortName] [nvarchar](10) NOT NULL,
	[CapitalCity] [nvarchar](20) NULL,
	[Type] [int] NOT NULL DEFAULT 2, --1 - 直辖市, 2 - 行政省, 3 - 自治区, 4 - 特别行政区
 CONSTRAINT [PK_KB_ChinaProvince] PRIMARY KEY CLUSTERED ([Key] ASC)) ON [PRIMARY]
GO
--KB_ChinaCityGeoInfo-----------------
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KB_ChinaCityGeoInfo]'))
DROP TABLE [KB_ChinaCityGeoInfo]
GO
CREATE TABLE [KB_ChinaCityGeoInfo](
	[Key] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
	[Name] [nvarchar](20) NOT NULL,
	[ProvinceKey] [uniqueidentifier] NOT NULL,
	[ParentKey] [uniqueidentifier] NULL,
	[RangeLevel] [int] NOT NULL DEFAULT 15,
	[TelePrefix] [nvarchar](10) NULL,
	[AreaCode] [nvarchar](10) NULL,
	[ZipCode] [nvarchar](10) NULL,
 CONSTRAINT [PK_KB_ChinaCityGeoInfo] PRIMARY KEY CLUSTERED ([Key] ASC)) ON [PRIMARY]
GO